using GLib;

namespace Malem {
	
	protected class InterfaceObject : GLib.Object, InterfaceIface {
		private Gee.ArrayList<JobObject> jobs;
		public string interfaceName {get;construct;}
		
		public InterfaceObject(string interfaceName) {
			this.interfaceName = interfaceName;
		}
		
		construct {
			jobs = new Gee.ArrayList<JobObject>();
		}

		public string  getInterfaceName() {
			return this.interfaceName;
		}

		public void addJob(JobObject job) {
			jobs.add(job);
			job.addSupportedInterface(this);
			this.onAddedJob(job.dbusName, job.dbusPath);
			stdout.printf("add job  %s[%s:%s]\n", this.interfaceName, job.dbusName, job.dbusPath);
		}
		
		public void removeJob(JobObject job, bool isCompleted) {
			this.onRemovingJob(job.dbusName, job.dbusPath, isCompleted);
			jobs.remove(job);
			job.removeSupportedInterface(this);
		}
		
		public string[] getCurrentJobs(out uint32 count) {
			int i=0;
			string[] dbus_url = new string[jobs.size];
			count = jobs.size;
			foreach(JobObject job in this.jobs) {
				dbus_url[i] = job.dbusName+":"+job.dbusPath;
				i++;
			}
			return dbus_url;
		}
	}

}
